package org.example.module.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Date;

/**
 * 返回参数统一化
 *
 * @param <T>
 * @author yinjunwu
 */
@ApiModel(value = "全局响应参数", description = "全局响应参数")
@Getter
@Setter
@ToString
public class Response<T> {

    @ApiModelProperty(value = "状态码", name = "code", example = "200")
    private String code;
    @ApiModelProperty(value = "提示信息", name = "msg", example = "请求成功")
    private String msg;
    @ApiModelProperty(value = "时间戳", name = "time", example = "2021-10-10 11:12:10")
    private Date time;
    @ApiModelProperty(value = "数据项", name = "data")
    private T data;

    public Response(T data) {
        this.code = SysHttpStatus.SUCCESS.getCode();
        this.msg = SysHttpStatus.SUCCESS.getMsg();
        this.data = data;
        this.time = new Date();
    }

    public Response(T data, String msg) {
        this.code = SysHttpStatus.SUCCESS.getCode();
        this.msg = msg;
        this.data = data;
        this.time = new Date();
    }

    public Response(T data, String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.time = new Date();
    }
}
